/**
 * 修改教师的详细信息
 * 
 * /admin/teacher/update
 */

const User_info = require('../../../models/usersInfo')
const utils = require('../../../utils/index')
const $ = require('../../../utils/common')

const update_student_datail = async function (req, res) {
    try {
        delete req.body.user_password
        delete req.body.user_role

        // user_phone 格式
        if (req.body.user_phone){
            if (!$.isValuebalePhone(req.body.user_phone)) {
                $.sendMessage(res, 1015, '参数user_phone为有效手机号码')
                return
            }
        }
        // user_email 格式
        if (req.body.user_email) {
            if (!$.isValuableEmail(req.body.user_email)) {
                $.sendMessage(res, 1015, '参数user_email为有效邮箱地址')
                return
            }
        }

        user_updata = await User_info.update(req.body, {
            where: {
            id: req.body.id
            }
        })
        
        // 修改不成功
        if (user_updata[0] == 0) {
            $.sendMessage(res, 1016, '修改失败')
            return
        }

        else if (user_updata[0] == 1) {
            $.sendMessage(res, 200, '修改成功')
        }
        
        // 日志
        utils.create_a_log(req, '教师详情', '修改')
        return

    } catch(error) {
        $.sendMessage(res, '1019', 'error' + error)
        utils.create_a_log(req, '教师详情', '修改', '失败')
        return
    }
}
    
module.exports = update_student_datail